﻿<UserControl x:Class="MContracts.View.NtpProblemView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="600">

    <Expander Background="{StaticResource Expander-Background-Problems-Brush}" IsExpanded="{Binding IsMaximized, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
        
        <Expander.Header>
            <WrapPanel>
                <Image Source="/MContracts;component/Images/company_dnd.png" Width="30"></Image>
                <Label>Проблемы</Label>
            </WrapPanel>
        </Expander.Header>
        
        <Expander.Content>
            <Border BorderThickness="4" CornerRadius="4" Padding="2" Background="{StaticResource ResourceKey=Expander-Background-Brush}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition></ColumnDefinition>
                        <ColumnDefinition Width="35"></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                    </Grid.ColumnDefinitions>

                    <DockPanel LastChildFill="True" Margin="2">

                        <StackPanel DockPanel.Dock="Left" Width="1"/>
                        <StackPanel DockPanel.Dock="Right" Width="1"/>
                         
                        <DataGrid MouseDoubleClick="TroublesDataGrid_MouseDoubleClick" 
                                  VerticalGridLinesBrush="Transparent" ItemsSource="{Binding Path=ContractTroublesBindingList, Mode=OneTime}"
                                  CanUserAddRows="False" HeadersVisibility="Column" HorizontalScrollBarVisibility="Disabled" AutoGenerateColumns="False" x:Name="TroublesDataGrid">
                            <DataGrid.Columns>
                                <DataGridTemplateColumn Header="Проблема" Width="*">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <DockPanel LastChildFill="True">
                                                <StackPanel DockPanel.Dock="Left" Width="1"/>
                                                <StackPanel DockPanel.Dock="Right" Width="1"/>
                                                <TextBlock Text="{Binding Mode=OneTime}" DockPanel.Dock="Top" TextWrapping="WrapWithOverflow"/>
                                            </DockPanel>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn> 
                            </DataGrid.Columns>
                        </DataGrid>

                    </DockPanel>

                    <StackPanel Grid.Column="1" VerticalAlignment="Center">
                        <Button Style="{StaticResource Flat}" Margin="3" Click="Button_Click">
                            <Image Source="/MContracts;component/Resources/Back.png" ToolTip="Добавить проблему"></Image>
                        </Button>

                        <Button Margin="3" Style="{StaticResource Flat}" Click="Button_Click_1">
                            <Image Source="/MContracts;component/Resources/Forvard.png" ToolTip="Убрать из списка"></Image>
                        </Button>
                    </StackPanel>

                    <Border BorderBrush="Gray" Grid.Column="2" BorderThickness="1" CornerRadius="2">
                        <StackPanel>
                            <StackPanel.ScrollOwner>
                                <ScrollViewer />
                            </StackPanel.ScrollOwner>
                            <Label Content="Реестр проблем:"/>
                            <ComboBox Grid.ColumnSpan="3" Margin="3" ItemsSource="{Binding Troublesregistres}" SelectedItem="{Binding SelectedTroublesRegistry, Mode=TwoWay}">
                                <ComboBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel>
                                            <TextBlock Text="{Binding Name}" FontWeight="Bold"></TextBlock>
                                            <WrapPanel Margin="5">
                                                <TextBlock Text="Утверждено "></TextBlock>
                                                <TextBlock Text="{Binding StringFormat=\{0:d\}, Path=Approvedat}" Foreground="DarkGreen"></TextBlock>
                                                <TextBlock Text=", приказ "></TextBlock>
                                                <TextBlock Text="{Binding Ordernum}" Foreground="DarkGreen"></TextBlock>
                                                <TextBlock Text=", действует с "></TextBlock>
                                                <TextBlock Text="{Binding StringFormat=\{0:d\}, Path=Validfrom}" Foreground="DarkGreen"></TextBlock>
                                                <TextBlock Text=" по "></TextBlock>
                                                <TextBlock Text="{Binding StringFormat=\{0:d\}, Path=Validto}" Foreground="DarkGreen" ></TextBlock>
                                            </WrapPanel>
                                        </StackPanel>
                                    </DataTemplate>
                                </ComboBox.ItemTemplate>
                            </ComboBox>
                            
                            <StackPanel Orientation="Horizontal" Margin="3" VerticalAlignment="Center">
                                <TextBlock Text="Введите № проблемы" Margin="3" VerticalAlignment="Center"/>
                                <TextBox Width="40" Margin="3" VerticalAlignment="Center" x:Name="TroubleTextBox"/>
                                <Button ToolTip="Добавить проблему" Margin="3" VerticalAlignment="Center" Command="{Binding AddTroubleCommandByNumber}" CommandParameter="{Binding Path=Text, ElementName=TroubleTextBox}">
                                    <Image Source="/MContracts;component/Resources/Back.png" Width="24" Height="24"/>
                                </Button> 
                            </StackPanel>
                            
                            <DockPanel LastChildFill="True">
                                <StackPanel DockPanel.Dock="Left" Width="1"/>
                                <StackPanel DockPanel.Dock="Right" Width="1"/>
                                <ScrollViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="155" VerticalScrollBarVisibility="Auto">
                                <TreeView Margin="3" MouseDoubleClick="TroublesTreeView_MouseDoubleClick"
                                      Visibility="{Binding VisibilityTreeView}" 
                                      ItemsSource="{Binding Path=Troubles}" x:Name="TroublesTreeView" ScrollViewer.HorizontalScrollBarVisibility="Disabled" HorizontalContentAlignment="Left">
                                    <TreeView.ItemTemplate>
                                        <HierarchicalDataTemplate ItemsSource="{Binding Troubles}">
                                            <DockPanel LastChildFill="True">
                                                <StackPanel DockPanel.Dock="Left" Width="1"/>
                                                <StackPanel DockPanel.Dock="Right" Width="1"/>
                                                <TextBlock Text="{Binding}" TextWrapping="WrapWithOverflow"/>
                                            </DockPanel>
                                        </HierarchicalDataTemplate>
                                    </TreeView.ItemTemplate>
                                </TreeView>
                                </ScrollViewer>
                            </DockPanel>
                        </StackPanel>
                    </Border>

                </Grid>
            </Border>
        </Expander.Content>
    </Expander>
</UserControl>
